import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义状态对象的类型
interface State {
    isCollapse: boolean;
    studentId: string;
    studentPw: string;
    rememberMe: boolean;
}
function initState(): State {
    return {
        //这里写状态对象
        isCollapse: false, // 用于跟踪菜单是否折叠的布尔值
        studentId: '',
        studentPw: '',
        rememberMe: false,
    }
}

export const useAllDataStore = defineStore('allData', () => {
    // 创建一个对状态对象的响应式引用
    const state = ref(initState())
    // 定义一个函数来更新状态对象
    function updateState(newState: Partial<State>) {
        state.value = { ...state.value, ...newState };
    }
    function updateRememberMe(newRememberMe: boolean) {
        state.value.rememberMe = newRememberMe;
    }
    // 返回状态
    return {
        state,
        updateState,
        updateRememberMe,
    };
})